import { PageParam } from '@/services/common'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface NotifyVO {
  /**
   * id
   */
  id: string
  /**
   * 通知类型
   */
  notifyType: string
  /**
   * webhook地址
   */
  webhookUrl: string
  /**
   * 备注
   */
  remark: string
}

export interface NotifyQueryDTO extends PageParam {
  /**
   * id
   */
  id?: string
  /**
   * 通知类型
   */
  notifyType?: string
  /**
   * webhook地址
   */
  webhookUrl?: string
  /**
   * 备注
   */
  remark?: string
}

export interface NotifyUpdateDTO {
  /**
   * id
   */
  id?: string
  /**
   * 通知类型
   */
  notifyType?: string
  /**
   * webhook地址
   */
  webhookUrl?: string
  /**
   * 备注
   */
  remark?: string
}

export const getNotifyById = async (id: string) => {
  return request<NotifyVO>(`/api/notify?id=${id}`, { method: 'GET' })
}

export const getNotifyList = async (params?: NotifyQueryDTO) => {
  return request<Array<NotifyVO>>(`/api/notify/list`, { method: 'GET', params })
}

export const getNotifyPage = async (params: NotifyQueryDTO) => {
  let response = await request<Array<NotifyVO>>(`/api/notify/page`, { method: 'GET', params })
  return covertTableData(response)
}

export const updateNotify = async (notifyUpdateDTO: NotifyUpdateDTO) => {
  return request<NotifyVO>(`/api/notify/update`, { method: 'POST', data: notifyUpdateDTO })
}

export const saveNotify = async (notifyUpdateDTO: NotifyUpdateDTO) => {
  return request<NotifyVO>(`/api/notify/save`, { method: 'POST', data: notifyUpdateDTO })
}

export const removeNotify = async (id: string) => {
  return request<boolean>(`/api/notify/remove?id=${id}`, { method: 'POST' })
}
